<?php

include '../../../configuration.php';

include 'sorting.php';


$smarty->template_dir = LOCAL_PATH.'administrator/main/templates/';
$smarty->compile_dir = LOCAL_PATH.'administrator/main/templates_c/';
$smarty->config_dir = LOCAL_PATH.'administrator/main/configs';

$smarty->compile_check = true;
//$smarty->debugging = true;
$faculties = array();
$result2 = mysql_query("SELECT * FROM `faculties`");
while ($rows = mysql_fetch_array($result2, MYSQL_ASSOC)){
	$faculties[$rows["faculty_id"]] = $rows["faculty_name"];
}


$q_id = array();
$q_title = array();
$f_title = array();
$q_complexity = array();
$cat_title = array();
$q_cdate = array();
$q_udate = array();

while ($rows = mysql_fetch_array($result,MYSQL_ASSOC)){
	$q_id[] = $rows["q_id"];
	$q_title[] = $rows["q_title"];
	$cat_title[] = $rows["cat_title"];
	$f_ids = $rows["faculty_ids"];
	$str = explode(",",$f_ids);
	$text = "";
	foreach( $str as $k ){
		$text .= $faculties[$k].",";
	}
	$text = substr($text,0, strlen($text)-1);
	$f_title[] = $text;
	$q_complexity[] = $rows["q_complexity"];
	$q_cdate[] = $rows["q_cdate"];
	$q_udate[] = $rows["q_udate"];
}
$categories = array("<option value='all'>All categories</option>");
$result3 = mysql_query("SELECT * FROM `categories`");

while ($rows3 = mysql_fetch_array($result3,MYSQL_ASSOC)) {
	$selected = '';
	if ($_SESSION['selected_cat']==$rows3["cat_id"]){
		$selected = "selected='true'";
	}
	$categories[] = "<option value='".$rows3["cat_id"]."' $selected >".$rows3["cat_title"]."</option>";
}

$faculties = array("<option value='all'>All faculties</option>");
$result4 = mysql_query("SELECT * FROM `faculties`");

while ($rows4 = mysql_fetch_array($result4,MYSQL_ASSOC)) {
	$selected = '';
	if($_SESSION['selected_f'] == $rows4["faculty_id"]){
		$selected = "selected='true'";
	}
	$faculties[] = "<option value='".$rows4["faculty_id"]."' $selected >".$rows4["faculty_name"]."</option>";
}

$result5 = mysql_query($t_sql);
$rows5 = mysql_num_rows($result5);
$_SESSION['q_count'] = $rows5;

$pages = ceil($_SESSION['q_count']/$_SESSION['m_limit']);
$smarty->assign('q_id',$q_id);
$smarty->assign('q_title',$q_title);
$smarty->assign('cat_title',$cat_title);
$smarty->assign('q_complexity',$q_complexity);
$smarty->assign('f_title',$f_title);
$smarty->assign('q_cdate',$q_cdate);
$smarty->assign('q_udate',$q_udate);
$smarty->assign('limit',$_SESSION['m_limit']);
$smarty->assign('comp',$_SESSION['selected_comp']);
$smarty->assign('selected_cat',$_SESSION['selected_cat']);
$smarty->assign('categories',$categories);
$smarty->assign('faculties',$faculties);
$smarty->assign('pages',$pages);

$smarty->assign('date',date('Y-m-d'));

include '../../check.php';
if ($checking == 1)
	$smarty->display('modify_question_1.tpl');
else echo "You are not autorised"; exit;

?>
